package com.encryption;

import cn.sunline.openapi.utils.SM2.*;
import cn.sunline.openapi.utils.sftp.*;
import lombok.var;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.IOException;
import java.util.Map;

@SpringBootApplication
public class EncryptionApplation {
    public static final String PUBLICKEY = "publicKey";
    public static final String PRIVATEKEY = "privateKey";

    public static void main(String[] args) throws Exception {
        //生成密钥对
        Map<String, String> map = SM2Util.generateKeyPair();
        String prik = map.get(PRIVATEKEY);
        String pubk = map.get(PUBLICKEY);
        System.out.println("公钥：" + pubk);
        System.out.println("私钥：" + prik);
        String plainText = "老周加油啊哈哈哈哈哈asdf";
        System.out.println("原始: ");
        System.out.println(plainText);
        byte[] sourceData = plainText.getBytes();
        // 国密规范正式私钥
//        String prik = "3690655E33D5EA3D9A4AE1A1ADD766FDEA045CDEAA43A9206FB8C430CEFE0D94";
//        // 国密规范正式公钥
//        String pubk = "04F6E0C3345AE42B51E06BF50B98834988D54EBC7460FE135A48171BC0629EAE205EEDE253A530608178A98F1E19BB737302813BA39ED3FA3C51639D7A20C7391A";
        System.out.println("加密: ");
        String cipherText = SM2Util.encrypt(ByteUtils.hexToByte(pubk), sourceData);
        System.out.println(cipherText);
        System.out.println("解密: ");
        plainText = new String(SM2Util.decrypt(ByteUtils.hexToByte(prik), cipherText));
        System.out.println(plainText);
        System.out.println("SM2 - EncryptionApplation - runing");

//        byte[] signedData = SM2Util.signUseCfca("datree-work", sourceData);
//        System.out.println("签名signedData:");
//        System.out.println(new String(signedData));
//        byte[] validedData = SM2Util.verifyUseCfca("datree-work", signedData);
//        System.out.println("验签validedData:");
//        System.out.println(new String(validedData));
    }
}














